﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.SessionState;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Text;
using System.IO;
using BarcodeLib;

namespace CanDooWebHost
{
    public partial class barcode : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var code = Request.QueryString["barcode"].ToString();
                CreateBarCodeImage(code);
            }
        }

        private void CreateBarCodeImage(string barcode)
        {
            BarcodeLib.Barcode b = new Barcode();
            b.Encode(TYPE.CODE128, barcode);
            System.Drawing.Image image = b.EncodedImage;

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            Response.ClearContent();
            Response.BinaryWrite(ms.ToArray());
        }
    }
}